import java.util.Scanner;

public class Q2 {
    public static int maxSubArraySum(int[] nums) {
        int currentMax = nums[0];
        int globalMax = nums[0];

        for (int i = 1; i < nums.length; i++) {
            currentMax = Math.max(nums[i], currentMax + nums[i]);
            globalMax = Math.max(globalMax, currentMax);
        }
        return globalMax;
    }

    public static void main(String[] args) {
        Scanner sc = null;
        try {
            sc = new Scanner(System.in);

            int length = sc.nextInt();

            int[] arr = new int[length];
            for (int i = 0; i < length; i++){
                arr[i] = sc.nextInt();
            }
            System.out.println(maxSubArraySum(arr));
        }  finally {
            if (sc != null) {
                sc.close();
            }
        }
    }
}
